Cartdev 32X

First Time Users

To run the cartdev demo, do the following from coldstart:

CD into the "CARTDEV" directory.
Run "HSITL32.EXE" from the command prompt
type : @start	;This is a batch program to download and start a rom image.
type : Q		;Quit out to DOS.

CD into the cross directory from the root
Run "SNBUG32X.EXE" - this is the cross products debugger

Once in the debugger, the following keys will need to be pressed :

	Press number 4 to enable the 68000 target
	Press number 2 to enable the SH2 SUB target
	Press number 1 to enable the SH2 MAIN target

If a "LINK ERROR" occurs on the shipped binary, one of the following could be the cause:

1) The target was in an undefined state. Power down the target/cartdev and try again.
2) The Cartdev NMI cable isnt hooked up - check that the silver wire is connected.
3) The cartdev power switch isnt turned on.
4) You are running on a version 1.1 32x target. Run the "start11" script from HSITL32, not the "START" script. 

If the "HSITL32" program complains about ASPI, one of the following could be the cause :

1) An ASPI SCSI driver isnt installed. We have/provide the ADAPTEC ASPI driver.
2) The CARTDEV wasnt recognized as being a SCSI device - If you have the "/D" command on the ASPI command line, a cartdev device should be found and mounted.
3) The "FOUR BLUE DIPSWITCHS" are not set correct - These should ALL be in the OFF position.

If the debugger complains about the "message system", the following could be the cause.

1) You have share loaded. The debugger will not run with share loaded.
2) You might not have enough files/buffers in your config.sys.

Installing The Debugger
   
	Due to the severe restrictions of the 32X, this version of the debugger is designed to work around them at the cost of memory usage. The end of this document contains information on where the cartdev hardware and software is going in the future. 

	This distribution ZIP contains a directory called "DEBUGGER". In this directory are THREE binaries that represent the target side communication for cartdev. These binaries, along with some other changes, need to be integrated into your project.

The binaries are :
MON68K.BIN - 68000 monitor program
MONSH2M.BIN - SH2 MAIN monitor program
MONSH2S.BIN - SH2 SUB monitor program

Because of the multi-processing nature of the 32X, ALL three monitors must be installed before the system will function properly. Each monitor should be bound to your rom image and moved to the correct address. Once moved, a call to the monitor will initialize a given CPU. The code to do this is provided below in each CPU's section. GOOD LUCK! 

	Many of the problems people have installing the debugger are related to their project not working standalone. The best technique is to get you program running without the debuggers, then install them. In most cases this works the first time.

Some Common causes of a 32X program not working are:

1) Your start address is encoded wrong. the correct start address is $3f0 for the rev 2.0 "ICD_MARS". The rev 1.1 32x used $400 as a start address as well as a different "ICD_MARS".
2) The code after your ICD_MARS code is NOT PC relative. After the ICD_MARS code runs, the PC/cart is located at $880000 Not $000000 anymore. Make sure your program can adjust to this. 
3) The position of the ICD_MARS code is wrong. If the white sega text remains on the screen, then this is happening.    
4) Use the code below to determine if your 68000 is starting up. This code will set the background color to white.
	COLORTEST	MOVE.L #$C0000000,$C00004 ;Only works on the 68000.
			MOVE.W #$FFFF,$C00000
 Use this code to locate the failure point on the 68000. 
5) If your failing before the "BCS" after the ICD_MARS program, then odds are that your target may be bad. Try running the working cartdev demo.
6) If your failure point is waiting for the M_OK or the S_OK, then the SH2's arent working yet. The 32x SH2 boot rom writes these if its happy about the ICD block and the 32x SH2 header located at $3c0-$3ef. Common header problems are putting the start address as SDRAM, insted of the offset from the start of SDRAM. Check these against the working cartdev demo supplied.   
7) The SH2's VBR table is wrong. Check and recheck against the working program supplied.
8) Try turning on the frame buffer on the master sh2 to give feedback regarding its state.
9) Both sh2's must be "happy". Its possible for the slave CPU to lock the bus from the master and vice versa. Both sh2's must be working before your code will be stable.
     
68000 Monitor

The 68000 Monitor is designed to reside in WORK MEMORY at address $FF0000-$FF1FFF.
	
	This monitor code communicates through Dual Ported RAM located at $7E000-$7FFFF in the ROM. This address corresponds to the HIGHEST 8K of the FIXED bank in the 32X Mode. Be sure that your program doesn't corrupt/use this area.

The 68000 Monitor has TWO addresses of importance :
	$FF0000 - This is the INIT routine for the 68000 monitor.
	$FF0004 - This is the NMI/TRAP/ERROR routine.

The 68000 Monitor needs the following vectors captured in GENESIS mode AND 32X mode( The JMP tables). The Monitor INIT routine will set these vectors for you, as long as the rom isn't write protected. The preferred method is to install the vectors in your program, and write protect the ROM. 

The vectors that should be setup are :

VECTOR #	TYPE					VECTOR TO
EX#$2		BUS ERROR			-	$02FF0004
EX#$3		ADDRESS ERROR		-	$03FF0004
EX#$4		ILLEGAL INSTRUCTION	-	$04FF0004
EX#$5		DIVIDE BY ZERO		-	$05FF0004
EX#$6		CHK INSTRUCTION		-	$06FF0004
EX#$7		TRAPV INSTRUCTION		-	$07FF0004
EX#$8		PRIVLEDGE VIOLATION	-	$08FF0004
EX#$9		TRACE				-	$09FF0004
EX#$1F	NMI				-	$1FFF0004
EX#$20	TRAP 0 			-	$20FF0004
EX#$21	TRAP 1 			-	$21FF0004
EX#$22	TRAP 2 			-	$22FF0004
EX#$23	TRAP 3 			-	$23FF0004
EX#$24	TRAP 4 			-	$24FF0004
EX#$25	TRAP 5 			-	$25FF0004
EX#$26	TRAP 6 			-	$26FF0004
EX#$27	TRAP 7 			-	$27FF0004
EX#$28	TRAP 8 			-	$28FF0004
EX#$29	TRAP 9 			-	$29FF0004
EX#$2A	TRAP 10 			-	$2AFF0004
EX#$2B	TRAP 11			-	$2BFF0004
EX#$2C	TRAP 12 			-	$2CFF0004
EX#$2D	TRAP 13 			-	$2DFF0004
EX#$2E	TRAP 14			-	$2EFF0004
EX#$2F	TRAP 15			-	$2FFF0004
  
A note about the vectors used on the 68000. The highest BYTE of the 68000's vector is used for determining what VECTOR the 68000 came from. because the 68000 uses 24 bit addresses, this byte is ignored. Without the full 32 bit address as the vector, the monitor will not function. 

Two pieces of code must be installed in your 68000 program. The first is used to copy the monitor to the correct address and INIT the 68000 monitor. This should be done at the start of your program.   

			
Install_Mon_68000
			lea		monitor_68000,a0	
			move.l	#$ff0000,a1
			move.l	#(monitor_68000_end-monitor_68000)/4,d7
@move_mon
			move.l	(a0)+,(a1)+			;Copy the monitor
			dbra		d7,@move_mon

			jsr		$ff0000			;Init Monitor
			


The second piece of code will include the monitor into your program.


			cnop	0,4				;align to Lword boundary
monitor_68000
			incbin	mon68k.bin

			cnop	0,4				;align to Lword boundary
monitor_68000_end


Once these have been installed, your 68000 monitor is ready to communicate with the SH2's. If this isnt clear, looking at the sample provided should fill in the missing pieces.

 
SH2 MAIN Monitor



The SH2 main monitor is designed to reside in SDRAM at address $0603F000-$0603F7FF.  
	This monitor is designed to communicate with the 68000 through the COMMUNICATION PORTS of the 32x. Because of the design of the monitor, this communication happens transparently. This has the outward appearance of the monitor NOT using ANY communication ports.


The SH2 MAIN monitor has eight addresses of importance:
	$0603F000	-	This is the INIT routine for the SH2 MAIN.
	$0603F004	-	Exception 4 vector
	$0603F008	-	Exception 6 vector
	$0603F00C	-	Exception 9 vector
	$0603F010	-	Exception 10 vector
	$0603F014	-	Exception 11 vector
	$0603F018	-	Exception 12 vector
	$0603F01C	-	Exception 32 vector

 
The SH2 MAIN monitor needs the following vectors captured. The SH2 MAIN init routine will set these vectors in the VBR. The preferred method is to install them in your program.


The vectors that should be setup are :

VBR INDEX	TYPE					VECTOR TO
$0010		ILLEGAL INSTRUCTION		$0603F004
$0018		INVALID SLOT INSTRUCTION	$0603F008
$0024		CPU ADDRESS ERROR			$0603F00C
$0028		DMA ADDRESS ERROR			$0603F010
$002C		NMI VECTOR				$0603F014
$0030		USER BREAK VECTOR			$0603F018
$0080		TRAP #32				$0603F01C

 
Two pieces of code must be installed in your SH2 MAIN program. The first is used to copy the monitor to the correct address and INIT the SH2 MAIN monitor. This should be done at the start of your program.   

Install_mon_sh2m
			mov.l		#(monitor_sh2m_end-monitor_sh2m)/4,r3
			mov.l		#monitor_sh2m,r1
			mov.l		#$0603f000,r2
@mon_move
			mov.l		@r1+,r0
			mov.l		r0,@r2		;copy the monitor
			add.l		#4,r2
			dt		r3
			bf		@mon_move
			mov.l		#$0603f000,r0	;call the INIT routine
			jsr		@r0
			nop


The second piece of code will include the monitor into your program.


			.align	4			;align to Lword boundary
monitor_sh2m
			incbin	monsh2m.bin

			.align	4			;align to Lword boundary
monitor_sh2m_end


   
The sh2s have a documented problem with IRQ's/NMI's. Because the debugger is based on continuous interrupts to the 32x, you must have this fix included in your program in order for the sh2 monitor to operate properly.
	If you arent aware of this problem, please reference tech note #2 (THE UNIFIED IRQ HANDLER). The demo provided is using this method, so you may also reference the code.  




SH2 SUB Monitor



The SH2 main monitor is designed to reside in SDRAM at address $0603F800-$0603FFFF.  

	This monitor is designed to communicate with the 68000 through the COMMUNICATION PORTS of the 32x. Because of the design of the monitor, this communication happens transparently. This has the outward appearance of the monitor NOT using ANY communication ports.

The SH2 SUB monitor has eight addresses of importance:
	$0603F800	-	This is the INIT routine for the SH2 SUB.
	$0603F804	-	Exception 4 vector
	$0603F808	-	Exception 6 vector
	$0603F80C	-	Exception 9 vector
	$0603F810	-	Exception 10 vector
	$0603F814	-	Exception 11 vector
	$0603F818	-	Exception 12 vector
	$0603F81C	-	Exception 32 vector

 
The SH2 SUB monitor needs the following vectors captured. The SH2 SUB init routine will set these vectors in the VBR. The preferred method is to install them in your program.


The vectors that should be setup are :

VBR INDEX	TYPE					VECTOR TO
$0010		ILLEGAL INSTRUCTION		$0603F804
$0018		INVALID SLOT INSTRUCTION	$0603F808
$0024		CPU ADDRESS ERROR			$0603F80C
$0028		DMA ADDRESS ERROR			$0603F810
$002C		NMI VECTOR				$0603F814
$0030		USER BREAK VECTOR			$0603F818
$0080		TRAP #32				$0603F81C

Two pieces of code must be installed in your SH2 SUB program. The first is used to copy the monitor to the correct address and INIT the SH2 SUB monitor. This should be done at the start of your program.   

Install_mon_sh2s
			mov.l		#(monitor_sh2s_end-monitor_sh2s)/4,r3
			mov.l		#monitor_sh2s,r1
			mov.l		#$0603f800,r2
@mon_move
			mov.l		@r1+,r0
			mov.l		r0,@r2		;copy the monitor
			add.l		#4,r2
			dt		r3
			bf		@mon_move
			mov.l		#$0603f800,r0	;call the INIT routine
			jsr		@r0
			nop


The second piece of code will include the monitor into your program.


			.align	4			;align to Lword boundary
monitor_sh2m
			incbin	monsh2s.bin

			.align	4			;align to Lword boundary
monitor_sh2m_end


   
The sh2s have a documented problem with IRQ's/NMI's. Because the debugger is based on continuous interrupts to the 32x, you must have this fix included in your program in order for the sh2 monitor to operate properly. 
	If you arent aware of this problem, please reference tech note #2 (THE UNIFIED IRQ HANDLER). The demo provided is using this method, so you may also reference the code.


Problem Solving

Ive installed the monitors and I keep getting a LINKERROR from the debugger.

1) Does the sega standard "White copyright" appear on the screen ? If not, then your security code is failing. 
-You might have the wrong security for your version of the target. 
-The security code for ver 2.0 should start at address $3f0.	
-The security code for ver 1.0 should start at address $400
-Does your target work at all ? try running the supplied program or a cartridge.
2) Try removing the monitor init calls and see if your code runs on its own. Once your code works on its own, the monitor code should work.
3) Be sure your not corrupting the dual port ram in the FIXED bank on the 68000 side. Be sure your not using the memory the monitors reside in.

My monitors startup, but my IRQS stop happening after a while.

You havent installed the unified IRQ handler AND the free running timer code. Remember its a multi-part solution, having only one part wont fix the problem. Look at the supplied demo code, it has IRQs that work.

The debugger starts up OK, but after I run my code I get a LINKERROR.

1) Your code could be corrupting one of the monitors. try and narrow down what routine is causing the failure.
2) Your code could be corrupting the dual ported ram. Try and narrow down what routine is causing the failure.
3) Your code could be corrupting the VBR. Try and narrow down what routine is causing the failure.
Other Items of interest

	In the CARTDEV directory a program for downloading BIN files to cartdev is included. This program is called LC and comes without any guarantees. Currently this program doesn't enable dual port ram, so it cant be used in conjunction with the debugger.

	A useful script is provided in the CARTDEV directory. This script is called WRITEPR, and is used to write protect the ROM image from HSITL32.

	The next generation of cartdev software will NOT require you to include binary images or capture vectors with your code. We will be using a model closer to the current genesis debuggers, and one that is more accessible to all programmers. 
	This new model will allow the programmer to forget about security and genesis mode until the end of his project. The debugger will be a working cart image, and your code will download AROUND the debugger. You will only need to know as much or as little as you want about the cartdev system.    

  


        



